package inet.app.view.fragment;

import inet.app.R;
import inet.app.common.XoSoConstants;
import inet.app.model.object.Tk_Item;
import inet.app.model.util.ProgressDialog;
import inet.app.view.activity.MyApp;

import java.util.ArrayList;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;

public class FragmentTKDB extends BaseFragmentTK {
	private ProgressDialog pdia;
	private WebView webView;
	private ArrayList<Tk_Item> arraylist = new ArrayList<Tk_Item>();
	private String matinh = "XSTD", cuoc = " (Cước 1000đ)", selectTKDB, select,
			json = "";

	public static Fragment newInstance(Context context) {
		FragmentTKDB f = new FragmentTKDB();
		return f;
	}

	public static Fragment newInstance(Context context, String position) {
		FragmentTKDB f = new FragmentTKDB();
		Bundle args = new Bundle();
		args.putString("pos", position);
		f.setArguments(args);
		return f;
	}

	public static Fragment newInstance(Context context, String position,
			String json, String select) {
		System.out.println("RUn here ==== ...>>");
		FragmentTKDB f = new FragmentTKDB();
		Bundle args = new Bundle();
		args.putString("pos", position);
		args.putString("json", json);
		args.putString("select", select);
		f.setArguments(args);
		return f;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_tkdb,
				null);
		webView = (WebView) root.findViewById(R.id.webView);
		pdia = new ProgressDialog(getActivity());
		// Get Position
		if (getArguments() != null) {
			System.out.println("CHAY VAO 1");
			select = getArguments().getString("select");
			json = getArguments().getString("json");
		} else {
			System.out.println("cHAY VAO 2");
		}

		return root;
	}

	public void Load_data_webview_Tkdb(ArrayList<Tk_Item> arraylist) {
		System.out.println("RUNG THONG KE DAC BIET");
		// TODO Auto-generated method stub
		select = ((MyApp) mApplication).getSelectCode();
		selectTKDB = ((MyApp) mApplication).getSelectName();
		// Clear the cache
		webView.clearCache(true);
		String htmlClick = "", htmlTKDB = "", item = "", htmlfooter = "", listkq = "", cuoi = "";
		htmlClick += "<div  style=\"cursor: pointer; margin:3px 0 0 0; background-color:#323232;width: 100%\">"
				+ "<input style=\"background-color:#323232; color:#ffffff; height:30px; width:100%; font-size:11px; font-weight:bold; float:right; position:relative;\" type=\"button\" name=\"desel\" value=\""
				+ "Click Nhận Thống Kê Đặc Biệt"
				+ cuoc
				+ "\" onclick=\"window.location.href='"
				+ matinh
				+ "'\" >"
				+ "</div>";

		htmlTKDB += "<div style=\"margin:0 0 0 0; background-color:#EEEEEE; height:10px; text-align:center;\">"
				+ "<span style=\"background-color:#EEEEEE; text-align:center; position:relative; top:10px\" class=\"fontsize12\">"
				+ "</span>"
				+ "</div>"
				+

				"<div>"
				+ "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">"
				+ "<tr>"
				+

				"<td width=\"100%\" valign=\"top\" colspan=\"12\">"
				+

				"<table width=\"100%\"  border=\"0\" bgcolor=\"#CCCCCC\" cellspacing=\"1\" cellpadding=\"0\">"
				+

				"<tr bgcolor=\"#c9b7b7\" >"
				+ "<td width=\"18%\" height=\"25\"  align=\"center\" class=\"right\" style=\"color:back;\" colspan=\"12\" >"
				+ selectTKDB
				+ "</td>"
				+ "<td width=\"41%\" height=\"25\"  align=\"center\" class=\"right\" style=\"color:back;\" colspan=\"12\" >"
				+ "Ngày về"
				+ "</td>"
				+ "<td width=\"41%\" height=\"25\"  align=\"center\" class=\"right\" style=\"color:back;\" colspan=\"12\" >"
				+ "Chưa ra" + "</td>" + "</tr>";
		cuoi = ""

				+ "</table>"
				+

				"</td>"
				+ "</tr>"
				+ "</table>"
				+ "</div>"
				+ "<div style=\"margin:0 0 0 0; background-color:#EEEEEE; height:25px; text-align:center;\">"
				+ "<span style=\"background-color:#EEEEEE; text-align:center; position:relative; top:10px\" class=\"fontsize12\">"
				+ "</span>" + "</div>" +

				"</div>";

		for (int i = 0; i < arraylist.size(); i++) {
			listkq += ""
					+ "<tr bgcolor=\"#FFFFFF\" >"
					+ "<td width=\"18%\" height=\"25\"  align=\"center\" class=\"right\" style=\"color:back;\" colspan=\"12\" >"
					+ arraylist.get(i).getNumber()
					+ "</td>"
					+ "<td width=\"41%\" height=\"25\"  align=\"center\" class=\"right\" style=\"color:back;\" colspan=\"12\" >"
					+ arraylist.get(i).getDate()
					+ "</td>"
					+ "<td width=\"41%\" height=\"25\"  padding-left:align=\"left\" class=\"right\" style=\"color:back;\" colspan=\"12\" >"
					+ "\t"+arraylist.get(i).getChuara() + " ngày" + "</td>" + "</tr>";
		}

		htmlfooter = "<div style=\"margin:0 0 0 0; background-color:#323232; height:35px; text-align:center;\">"
				+ "<span style=\"background-color:#323232; text-align:center; color:#ffffff; font-size:13px; position:relative; top:10px\" class=\"fontsize12\">"
				+ "<strong>"
				+ "Chơi xổ số kiến thiết ích nước lợi nhà !"
				+ "</strong></span>" + "</div>";
		String giua;
		webView.loadDataWithBaseURL("file:///android_asset/", XoSoConstants.css + htmlClick + htmlTKDB + listkq + cuoi
				+ htmlfooter +"</body></html>", "text/html", "utf-8", null);

	}

	public void update() {

	}
}
